package com.lc.hot100.lc142;

import com.lc.utils.ListNode;


public class Main {

}
class Solution {
    public ListNode detectCycle(ListNode head) {
    	ListNode fast = head;
    	ListNode slow = head;
    	
    	while(fast != null) {
    		fast = fast.next;
    		slow = slow.next;
    		if (fast == null) {
    			return null;
    		} else {
    			fast = fast.next;
    		}
    		if (fast == slow) {
    	    	ListNode p = head;
    	    	while(p != fast) {
    	    		p = p.next;
    	    		fast = fast.next;
    	    	}
    	    	return p;
    		}
    	}
    	return null;
    }
}
